package com.yonsz.cloud.open.platform.model;

import lombok.Data;

import java.io.Serializable;

@Data
public class ApiResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private T data;

    private String msg;


    public ApiResult() {
    }


    public ApiResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 常用成功时候调用
     *
     * @return
     */
    public static <T> ApiResult<T> success(String msg, T data) {
        return new ApiResult<T>(1, msg, data);
    }

    /**
     * 常用成功时候调用
     *
     * @return
     */
    public static <T> ApiResult<T> success(int code, String msg, T data) {
        return new ApiResult<T>(code, msg, data);
    }

    /**
     * 常用失败时候调用
     *
     * @return
     */
    public static <T> ApiResult<T> error(String msg, T data) {
        return new ApiResult<T>(0, msg, data);
    }

    /**
     * 常用失败时候调用
     *
     * @return
     */
    public static <T> ApiResult<T> error(int code, String msg) {
        return new ApiResult<T>(code, msg, null);
    }


}
